<?php

/**
 * This is the model class for table "{{jamaah}}".
 *
 * The followings are the available columns in table '{{jamaah}}':
 * @property integer $id_laskar
 * @property string $nama
 * @property string $alamat_ktp
 * @property string $no_ktp
 * @property string $tempat_lahir
 * @property string $tgl_lahir
 * @property string $hp1
 * @property string $hp2
 * @property string $tlp_rumah
 * @property string $pin_bb
 * @property string $email
 * @property integer $sadziliyah
 * @property integer $qodiriyah
 * @property integer $lama_suluk
 * @property integer $id_kelompok
 * @property integer $status
 * @property integer $sa78
 * @property integer $laqodja
 * @property integer $jenis_kelamin
 * @property string $tgl_gabung
 *
 * The followings are the available model relations:
 * @property DesaAnggota[] $desaAnggotas
 * @property Kelompok $idKelompok
 * @property KabupatenAnggota[] $kabupatenAnggotas
 * @property KecamatanAnggota[] $kecamatanAnggotas
 * @property Kelompok[] $kelompoks
 * @property Kelompok[] $kelompoks1
 * @property Kelompok[] $kelompoks2
 * @property Kelompok[] $kelompoks3
 * @property Kelompok[] $kelompoks4
 * @property KelurahanAnggota[] $kelurahanAnggotas
 * @property Struktur[] $strukturs
 * @property Users[] $users
 */
class Jamaah extends CActiveRecord {

    public $nama_kabupaten;
    public $nama_kelompok;
    public $kode_lokasi;

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return '{{jamaah}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('nama, tgl_lahir', 'required'),
            array('sadziliyah, qodiriyah, lama_suluk, id_kelompok, status, sa78, laqodja, jenis_kelamin',
                'numerical', 'integerOnly' => true),
            array('nama, alamat_ktp, no_ktp, tempat_lahir', 'length', 'max' => 255),
            array('hp1, hp2, tlp_rumah, pin_bb', 'length', 'max' => 20),
            array('email', 'length', 'max' => 50),
            array('tgl_gabung', 'safe'),
            // The following rule is used by search().
            // @todo Please remove those attributes that should not be searched.
            array('id_laskar, nama, alamat_ktp, no_ktp, tempat_lahir, tgl_lahir, hp1, hp2, tlp_rumah, pin_bb, email, sadziliyah, qodiriyah, lama_suluk, id_kelompok, status, sa78, laqodja, jenis_kelamin, tgl_gabung,nama_kabupaten,nama_kelompok',
                'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'desaAnggotas' => array(self::HAS_MANY, 'DesaAnggota', 'id_laskar'),
            'idKelompok' => array(self::BELONGS_TO, 'Kelompok', 'id_kelompok'),
            'kabupatenAnggotas' => array(self::HAS_MANY, 'KabupatenAnggota', 'id_laskar'),
            'kecamatanAnggotas' => array(self::HAS_MANY, 'KecamatanAnggota', 'id_laskar'),
            'kelompoks' => array(self::HAS_MANY, 'Kelompok', 'wakil_ketua'),
            'kelompoks1' => array(self::HAS_MANY, 'Kelompok', 'imam'),
            'kelompoks2' => array(self::HAS_MANY, 'Kelompok', 'wakil_imam_1'),
            'kelompoks3' => array(self::HAS_MANY, 'Kelompok', 'wakil_imam_2'),
            'kelompoks4' => array(self::HAS_MANY, 'Kelompok', 'ketua'),
            'kelurahanAnggotas' => array(self::HAS_MANY, 'KelurahanAnggota', 'id_laskar'),
            'strukturs' => array(self::HAS_MANY, 'Struktur', 'laskar'),
            'users' => array(self::HAS_MANY, 'Users', 'id_laskar'),
            'idKabupaten' => array(self::HAS_ONE, 'Kabupaten', 'id_kabupaten', 'through' => 'idKelompok'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id_laskar' => 'Id Laskar',
            'nama' => 'Nama',
            'alamat_ktp' => 'Alamat Ktp',
            'no_ktp' => 'No Ktp',
            'tempat_lahir' => 'Tempat Lahir',
            'tgl_lahir' => 'Tgl Lahir',
            'hp1' => 'Hp1',
            'hp2' => 'Hp2',
            'tlp_rumah' => 'Tlp Rumah',
            'pin_bb' => 'Pin Bb',
            'email' => 'Email',
            'sadziliyah' => 'Sadziliyah',
            'qodiriyah' => 'Qodiriyah',
            'lama_suluk' => 'Lama Suluk',
            'id_kelompok' => 'Id Kelompok',
            'status' => 'Status',
            'sa78' => 'Sa78',
            'laqodja' => 'Laqodja',
            'jenis_kelamin' => 'Jenis Kelamin',
            'tgl_gabung' => 'Tgl Gabung',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     *
     * Typical usecase:
     * - Initialize the model fields with values from filter form.
     * - Execute this method to get CActiveDataProvider instance which will filter
     * models according to data in model fields.
     * - Pass data provider to CGridView, CListView or any similar widget.
     *
     * @return CActiveDataProvider the data provider that can return the models
     * based on the search/filter conditions.
     */
    public function search() {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id_laskar', $this->id_laskar);
        $criteria->compare('nama', $this->nama, true);
        $criteria->compare('alamat_ktp', $this->alamat_ktp, true);
        $criteria->compare('no_ktp', $this->no_ktp, true);
        $criteria->compare('tempat_lahir', $this->tempat_lahir, true);
        $criteria->compare('tgl_lahir', $this->tgl_lahir, true);
        $criteria->compare('hp1', $this->hp1, true);
        $criteria->compare('hp2', $this->hp2, true);
        $criteria->compare('tlp_rumah', $this->tlp_rumah, true);
        $criteria->compare('pin_bb', $this->pin_bb, true);
        $criteria->compare('email', $this->email, true);
        $criteria->compare('sadziliyah', $this->sadziliyah);
        $criteria->compare('qodiriyah', $this->qodiriyah);
        $criteria->compare('lama_suluk', $this->lama_suluk);
        $criteria->compare('id_kelompok', $this->id_kelompok);
        $criteria->compare('status', $this->status);
        $criteria->compare('sa78', $this->sa78);
        $criteria->compare('laqodja', $this->laqodja);
        $criteria->compare('jenis_kelamin', $this->jenis_kelamin);
        $criteria->compare('tgl_gabung', $this->tgl_gabung, true);

        $criteria->with = array('idKelompok', 'idKabupaten');
        $criteria->compare('nama_kabupaten', $this->nama_kabupaten, true);
        $criteria->compare('nama_kelompok', $this->nama_kelompok, true);
        $criteria->compare('idKabupaten.kode_lokasi', $this->kode_lokasi, true);
        return new CActiveDataProvider($this,
                array(
            'criteria' => $criteria,
        ));
    }

    /**
     * Returns the static model of the specified AR class.
     * Please note that you should have this exact method in all your CActiveRecord descendants!
     * @param string $className active record class name.
     * @return Jamaah the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

}
